package com.wpp.demo.controller;

import com.wpp.demo.common.Common;
import com.wpp.demo.service.DemoService;
import com.wpp.mvcframemwrok.annotation.Security;
import com.wpp.mvcframemwrok.annotation.WppAutowired;
import com.wpp.mvcframemwrok.annotation.WppController;
import com.wpp.mvcframemwrok.annotation.WppRequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author by wpp25
 * @Classname DemoController
 * @Description
 *
 * http://localhost:8080/demo/handle01?username=zhangsan
 * @Date 2020/10/22 21:59
 */
@WppController
@WppRequestMapping("/demo")
public class DemoController {

    @WppAutowired
    private DemoService demoService;

    @Security({Common.Security.SECURITY_ADMIN,Common.Security.SECURITY_USER})
    @WppRequestMapping("/handle01")
    public String handle01(HttpServletRequest request, HttpServletResponse response,String userName) {

        try {
            response.getWriter().write(userName + "....admin 权限");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return demoService.getName(userName);
    }

    @Security({Common.Security.SECURITY_USER})
    @WppRequestMapping("/handle02")
    public String handle02(HttpServletRequest request, HttpServletResponse response,String userName) {

        try {
            response.getWriter().write(userName + ".... user 权限");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return demoService.getName(userName);
    }


}
